---
title: "Untitled"
output: html_document
---
############################################
Title: 4_08_Table_8.rmd
Purpose: This code runs the baseline aggregate level regressions in Table 8 
Last updated: 19-04-2024

Input:
   - Baseline macro (From 2_01 Calculate Aggregate level macro data.rmd). Latest version: final_agg_macro_data_UPDATED2023_v2023-08-22.csv
   - HY Bond share (From 2_03 Calculate HY Bond Share.rmd). Latest version: "total_issuance_v2023-08-28.csv"
   - HY Loan share (From 2_04 Calculate HY Loan Share.rmd). Latest version: "C_B_loan_issuance_v2023-09-06.csv"
   
Output:
    - Table 8
  
##########################################




########################################## 
1. Setup
########################################## 

0. Setup *Set your file path here*
```{r, results="hide", include=FALSE}
#Clear user defined environment
rm(list=ls())
#Clear memory


#Load packages
require(stargazer); require(lubridate); library(sandwich); library(ggplot2); require(dplyr); require(tidyverse); library(readxl); library(sandwich); library(lmtest); library(psych)
require(quantmod); require(dynlm); require(AER); require(vars); require(forecast); require(stargazer); require(strucchange); require(xts); require(lubridate); require(fGarch); require(zoo); require(timeSeries); library(sandwich); require(car);library(fBasics); library(ggplot2); require(dplyr); require(tidyverse); library(readxl); library(sandwich); library(QuantPsyc); library(tseries); library(latticeExtra); library(corrplot); library(psych) ; library(stringr); library(readr); library(see)

#options
options(digits=5)
options(stringsAsFactors = FALSE)
options(scipen=999)

#Assign dplyr verbs  
select <- dplyr::select
rename <- dplyr::rename
mutate <- dplyr::mutate
filter <- dplyr::filter
arrange <- dplyr::arrange
distinct <- dplyr::distinct
group_by <- dplyr::group_by
summarise <- dplyr::summarise
list <- base::list

#Define directories
global <- ".../2024_RFS_Replication_TOSUBMIT"

```

1.1 Load data
```{r, include=FALSE, results='hide'}

#Load
final_agg_macro_data <- read_csv(paste0(global, "/Data/final_agg_macro_data_monthly.csv", ""), 
      col_types = cols(...1 = col_skip(), date = col_date(format = "%Y-%m-%d")))


```

1.2 Select time period
```{r, results="hide", include=FALSE}

#Select sample period
macrofin_m_2000_extd = subset(final_agg_macro_data, date > "1999-11-01" & date < "2023-04-01")  

#Exclude GFC
macrofin_m_2000_extd_excrisis = subset(macrofin_m_2000_extd, date < "2007-12-01" | date > "2009-03-01") 


```




########################################## 
3. Table 8 results
##########################################

3.1 OLS Reg: Panel A
```{r, include=FALSE, results='hide'}


mod_a = lm(lip_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma + termspr + ffr_r  + lip_1m_behind   + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_a = NeweyWest(lm(lip_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma +  termspr + ffr_r  + lip_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_a, vcov = nw_mod_a )
robust_mod_a = coeftest(mod_a, vcov = nw_mod_a)[,3]
coef_mod_a=lm.beta(mod_a)



mod_b = lm(ism_man_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma + termspr + ffr_r + ism_man_1m_behind + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_b = NeweyWest(lm(ism_man_3m_ahead ~ loan_spr_fd +C_B_share_3m_ma + termspr + ffr_r + ism_man_1m_behind  + first_pc_fd , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_b, vcov = nw_mod_b )
robust_mod_b = coeftest(mod_b, vcov = nw_mod_b )[,3]
coef_mod_b=lm.beta(mod_b)



mod_c = lm(ism_nonman_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma + termspr + ffr_r + ism_nonman_1m_behind + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_c = NeweyWest(lm(ism_nonman_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma + termspr + ffr_r + ism_nonman_1m_behind + first_pc_fd , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_c, vcov = nw_mod_c )
robust_mod_c = coeftest(mod_c, vcov = nw_mod_c )[,3]
coef_mod_c=lm.beta(mod_c)



mod_d = lm(tcu_3m_ahead ~ loan_spr_fd +  C_B_share_3m_ma + termspr + ffr_r  + tcu_1m_behind  + first_pc_fd  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_d = NeweyWest(lm(tcu_3m_ahead ~ loan_spr_fd +  C_B_share_3m_ma +  termspr + ffr_r  + tcu_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_d, vcov = nw_mod_d )
robust_mod_d = coeftest(mod_d, vcov = nw_mod_d)[,3]
coef_mod_d=lm.beta(mod_d)



mod_e = lm(lnew_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma  +   termspr + ffr_r  + lnew_1m_behind  + first_pc_fd  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_e = NeweyWest(lm(lnew_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma  + termspr + ffr_r  + lnew_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_e, vcov = nw_mod_e )
robust_mod_e = coeftest(mod_e, vcov = nw_mod_e)[,3]
coef_mod_e=lm.beta(mod_e)



mod_f = lm(linv_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma  +   termspr + ffr_r  + linv_1m_behind   + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_f = NeweyWest(lm(linv_3m_ahead ~ loan_spr_fd + C_B_share_3m_ma + termspr + ffr_r  + linv_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_f, vcov = nw_mod_f )
robust_mod_f = coeftest(mod_f, vcov = nw_mod_f)[,3]
coef_mod_f=lm.beta(mod_f)




stargazer(mod_a,  mod_d, mod_e, mod_f, mod_b, mod_c,
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("Industrial Production - 3m ahead"), 
          se = list( robust_mod_a, robust_mod_d, robust_mod_e, robust_mod_f,  robust_mod_b, robust_mod_c), 
          coef = list(coef_mod_a, coef_mod_d, coef_mod_e, coef_mod_f, coef_mod_b, coef_mod_c),
          omit = c( "Constant" ))


```

3.1 OLS Reg: Panel B
```{r, include=FALSE, results='hide'}


mod_a = lm(lip_3m_ahead ~ loan_spr_fd + HY_share_3m_ma + termspr + ffr_r  + lip_1m_behind   + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_a = NeweyWest(lm(lip_3m_ahead ~ loan_spr_fd + HY_share_3m_ma +  termspr + ffr_r  + lip_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_a, vcov = nw_mod_a )
robust_mod_a = coeftest(mod_a, vcov = nw_mod_a)[,3]
coef_mod_a=lm.beta(mod_a)


mod_b = lm(ism_man_3m_ahead ~ loan_spr_fd + HY_share_3m_ma + termspr + ffr_r + ism_man_1m_behind + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_b = NeweyWest(lm(ism_man_3m_ahead ~ loan_spr_fd + HY_share_3m_ma + termspr + ffr_r + ism_man_1m_behind  + first_pc_fd , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_b, vcov = nw_mod_b )
robust_mod_b = coeftest(mod_b, vcov = nw_mod_b )[,3]
coef_mod_b=lm.beta(mod_b)


mod_c = lm(ism_nonman_3m_ahead ~ loan_spr_fd + HY_share_3m_ma + termspr + ffr_r + ism_nonman_1m_behind + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_c = NeweyWest(lm(ism_nonman_3m_ahead ~ loan_spr_fd + HY_share_3m_ma + termspr + ffr_r + ism_nonman_1m_behind + first_pc_fd , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_c, vcov = nw_mod_c )
robust_mod_c = coeftest(mod_c, vcov = nw_mod_c )[,3]
coef_mod_c=lm.beta(mod_c)


mod_d = lm(tcu_3m_ahead ~ loan_spr_fd +  HY_share_3m_ma + termspr + ffr_r  + tcu_1m_behind  + first_pc_fd  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_d = NeweyWest(lm(tcu_3m_ahead ~ loan_spr_fd +  HY_share_3m_ma +  termspr + ffr_r  + tcu_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_d, vcov = nw_mod_d )
robust_mod_d = coeftest(mod_d, vcov = nw_mod_d)[,3]
coef_mod_d=lm.beta(mod_d)


mod_e = lm(lnew_3m_ahead ~ loan_spr_fd + HY_share_3m_ma  +   termspr + ffr_r  + lnew_1m_behind   + first_pc_fd , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_e = NeweyWest(lm(lnew_3m_ahead ~ loan_spr_fd + HY_share_3m_ma  + termspr + ffr_r  + lnew_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_e, vcov = nw_mod_e )
robust_mod_e = coeftest(mod_e, vcov = nw_mod_e)[,3]
coef_mod_e=lm.beta(mod_e)



mod_f = lm(linv_3m_ahead ~ loan_spr_fd + HY_share_3m_ma  +   termspr + ffr_r  + linv_1m_behind    + first_pc_fd, data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_f = NeweyWest(lm(linv_3m_ahead ~ loan_spr_fd + HY_share_3m_ma + termspr + ffr_r  + linv_1m_behind  + first_pc_fd, data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_f, vcov = nw_mod_f )
robust_mod_f = coeftest(mod_f, vcov = nw_mod_f)[,3]
coef_mod_f=lm.beta(mod_f)




stargazer(mod_a,  mod_d, mod_e, mod_f, mod_b, mod_c,
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("Industrial Production - 3m ahead"), 
          se = list( robust_mod_a, robust_mod_d, robust_mod_e, robust_mod_f,  robust_mod_b, robust_mod_c), 
          coef = list(coef_mod_a, coef_mod_d, coef_mod_e, coef_mod_f, coef_mod_b, coef_mod_c),
          omit = c( "Constant" ))


```

3.1 OLS Reg: Panel C
```{r, include=FALSE, results='hide'}

mod_lip = lm(lip_3m_ahead ~ loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix   + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + lip_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lip = NeweyWest(lm(lip_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix  + C_B_share_3m_ma + HY_share_3m_ma  + termspr + ffr_r  + lip_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lip, vcov = nw_mod_lip )
robust_mod_lip = coeftest(mod_lip, vcov = nw_mod_lip)[,3]
coef_mod_lip=lm.beta(mod_lip)



mod_ism_man = lm(ism_man_3m_ahead ~ loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + ism_man_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_man = NeweyWest(lm(ism_man_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix + C_B_share_3m_ma + HY_share_3m_ma  + termspr + ffr_r  + ism_man_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_man, vcov = nw_mod_ism_man )
robust_mod_ism_man = coeftest(mod_ism_man, vcov = nw_mod_ism_man)[,3]
coef_mod_ism_man=lm.beta(mod_ism_man)



mod_ism_nonman = lm(ism_nonman_3m_ahead ~   loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + ism_nonman_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_ism_nonman = NeweyWest(lm(ism_nonman_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + ism_nonman_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman )
robust_mod_ism_nonman = coeftest(mod_ism_nonman, vcov = nw_mod_ism_nonman)[,3]
coef_mod_ism_nonman=lm.beta(mod_ism_nonman)



mod_tcu = lm(tcu_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix   + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + tcu_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_tcu = NeweyWest(lm(tcu_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix   + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + tcu_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_tcu, vcov = nw_mod_tcu )
robust_mod_tcu = coeftest(mod_tcu, vcov = nw_mod_tcu)[,3]
coef_mod_tcu=lm.beta(mod_tcu)



mod_lnew = lm(lnew_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix   + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + lnew_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_lnew = NeweyWest(lm(lnew_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix  + C_B_share_3m_ma + HY_share_3m_ma  + termspr + ffr_r  + lnew_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_lnew, vcov = nw_mod_lnew )
robust_mod_lnew = coeftest(mod_lnew, vcov = nw_mod_lnew)[,3]
coef_mod_lnew=lm.beta(mod_lnew)



mod_linv = lm(linv_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix  + C_B_share_3m_ma + HY_share_3m_ma + termspr + ffr_r  + linv_1m_behind  , data = macrofin_m_2000_extd)
# NewwyWest standard errors
nw_mod_linv = NeweyWest(lm(linv_3m_ahead ~  loan_spr_fd + first_pc_fd + med_bidask + SP500_ret + mean_vix  + C_B_share_3m_ma + HY_share_3m_ma  + termspr + ffr_r  + linv_1m_behind , data = macrofin_m_2000_extd), lag = 4, prewhite = F, adjust = T)
coeftest(mod_linv, vcov = nw_mod_linv )
robust_mod_linv = coeftest(mod_linv, vcov = nw_mod_linv)[,3]
coef_mod_linv=lm.beta(mod_linv)




stargazer(mod_lip, mod_tcu, mod_lnew, mod_linv, mod_ism_man, mod_ism_nonman,
          type = "text", 
          align = TRUE, 
          #no.space = TRUE, 
          #dep.var.labels = c("coincident Index - 12m ahead"), 
          se = list(robust_mod_lip,  robust_mod_tcu, robust_mod_lnew, robust_mod_linv, robust_mod_ism_man, robust_mod_ism_nonman), 
          coef = list(coef_mod_lip,  coef_mod_tcu, coef_mod_lnew, coef_mod_linv, coef_mod_ism_man, coef_mod_ism_nonman),
          omit = c( "Constant" )
          )


```



